﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MyFound.Wpf.Models;

namespace MyFound.Wpf.Windows
{
    /// <summary>
    /// SaleWindow.xaml 的交互逻辑
    /// </summary>
    public partial class SaleWindow : Window
    {
        SaleFoundModel model=new SaleFoundModel();
        public SaleWindow()
        {
            InitializeComponent();

            Binding binding=new Binding("Count");
            binding.Source = model;
            TbCount.SetBinding(TextBox.TextProperty,binding);

            binding = new Binding("Found");
            binding.Source = model;
            cmbFound.SetBinding(Selector.SelectedValueProperty, binding);

            binding = new Binding("Equity");
            binding.Source = model;
            TbEquity.SetBinding(TextBox.TextProperty, binding);

            binding = new Binding("Fee");
            binding.Source = model;
            TbFee.SetBinding(TextBox.TextProperty, binding);

            binding = new Binding("DateTime");
            binding.Source = model;
            DpSaleDate.SetBinding(DatePicker.DisplayDateProperty, binding);
        }

        private void SaleWindow_OnLoaded(object sender, RoutedEventArgs e)
        {
            IEnumerable<Found> founds = Program.ListFound();
            cmbFound.ItemsSource = founds;
        }

        private void btnSale_Click(object sender, RoutedEventArgs e)
        {
            if (Validation.GetHasError(TbCount) || Validation.GetHasError(TbEquity) || Validation.GetHasError(TbFee))
                return;
            
            Program.SaleByFee(model.Found.Code,model.Count,model.Equity,model.Fee,model.DateTime);
        
        }
    }
}
